import { reqCommodity } from "@/api";
//search
//VUE中的四个核心概念
const state = {
    //存储数据
    searchInfo:{},
};
const mutations = {
    //直接修改数据
    RECEIVE_SEARCHINFO(state,searchInfo){
        state.searchInfo = searchInfo;
    }
};
const actions = {
    //与组件当中的用户对接
    //一般是异步发送请求
    //提交mutations
    async getSearchInfo({commit},searchParams){
        const result = await reqCommodity(searchParams);
        if(result.code === 200){
            commit("RECEIVE_SEARCHINFO",result.data);
        }
    }
};
const getters = {
    //后面用来简化数据的
    attrsList(state){
        return state.searchInfo.attrsList || []
    },
    goodsList(state){
        return state.searchInfo.goodsList || []
    },
    trademarkList(state) {
        return state.searchInfo.trademarkList || []
    }
}

export default{
    state,
    mutations,
    actions,
    getters,
};